define(['./../initial', './../service/showMsg'], function () {
    var app = angular.module('App.home');
    app.factory('Project.Extend.MonitorPoints', ['$q', '$http', 'showMsg', '$rootScope',
        function ($q, $http, showMsg, $rootScope) {

            var Extend = {};

            Extend.getMonitorPoints = function (queryCondition) {
                var _this = this;
                var defer = $q.defer();
                if (_this.monitorPoints && _this.monitorPoints.length > 0) {
                    defer.resolve(_this.monitorPoints);
                } else {
                    _this._requestHelper('get', 'getMonitorPoints').then(function (data) {
                        _this.monitorPoints = data;
                        defer.resolve(data);
                    });
                }
                return defer.promise;
            };

            Extend._getChanges = function (type, location, time1, time2, isDesign) {
                var _this = this;
                isDesign = typeof (isDesign) === 'undefined' ? false : isDesign;
                var defer = $q.defer();
                var url = 'recentChanges/' + type + '/' + encodeURIComponent(location) + '/' + time1 + '/' + time2 + '/1/' + isDesign;
                _this._requestHelper('get', url).then(function (data) {
                    defer.resolve(data);
                });
                return defer.promise;
            };

            Extend.getRecentChanges = function (type, location, time1, time2, isDesign) {
                var _this = this;
                isDesign = typeof (isDesign) === 'undefined' ? false : isDesign;
                if (type === '收敛') {//对于收敛要多查询一个同设计值相比最大变化点
                    return _this._getRecentDesignChanges(type, location, time1, time2);
                } else {
                    return _this._getChanges(type, location, time1, time2);
                }
            };

            Extend._getRecentDesignChanges = function (type, location, time1, time2) {
                var _this = this;
                var defer = $q.defer();
                $q.all([_this._getChanges(type, location, time1, time2, false),
                    _this._getChanges(type, location, time1, time2, true)])
                    .then(function (chordDatas) {
                        var data = chordDatas[0];
                        data.maxDesignPointAllTheTime = chordDatas[1].maxPointAllTheTime;
                        defer.resolve(data);
                    });
                return defer.promise;
            };

            Extend.getSinglePointChange = function (ptName, time1, time2) {
                var _this = this;
                var defer = $q.defer();
                var url = 'getSinglePointChange/' + encodeURIComponent(ptName) + '/' + time1 + '/' + time2;
                _this._requestHelper('get', url).then(function (data) {
                    defer.resolve(data);
                });
                return defer.promise;
            };


            return Extend;
        }
    ]);
});
